/**
 * Created by sunkejun on 2015/10/15.
 */

$(document).ready(function(){
    var table = new ComDataTable("/admin/sysparam/page",$('#dataTable'),"admin_sysparam");
    var renders = {
        id:admin_sysparam_list.editRender,
        photo_url:admin_sysparam_list.photo_render,
    };
    table.setRenders(renders);
    table.init();
    admin_sysparam_list.$table=table;
    //<span class="label label-primary">Enable</span>
})
var admin_sysparam_list  = (function ($) {
    this.editRender = function( data, type, full, meta ) {
        //return '<div class=" btn-group">'
        //    +'<a class="btn btn-xs btn-white" onclick="admin_sysparam_list.editTarget('+data+')" ><i class="fa fa-wrench"></i> </a>'
        //    +' <a class="btn btn-xs btn-white" onclick="admin_sysparam_list.delete('+data+')"><i class="fa fa-minus"></i> </a>'
        //    +'</div>';

        return   '<button class="btn btn-sm btn-warning"  tooltip="修改"  onclick="admin_sysparam_list.editTarget('+data+')" >  <span class="fa fa-edit"></span>  </button>'+
            '&nbsp;&nbsp<button class="btn btn-sm btn-danger"  tooltip="删除"   onclick="admin_sysparam_list.delete('+data+')">  <span class="fa fa-trash"></span></button>'
    }
    this.photo_render = function( data, type, full, meta ) {
        return '<img alt="image" id="navigation_headimg" class="img-circle" src="'+data+'">';
    }



    this.delete = function(id){
        swal({
            title: language.getNorlanguage().delete_title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: language.getNorlanguage().delete_sub,
            cancelButtonText: language.getNorlanguage().delete_cancle,
            closeOnConfirm: true,
            html: false
        }, function(){
            ComdataUtil.ajaxpostnormal('/admin/sysparam/'+id,{},function(data){
                this.$table.rdraw();
            },"DELETE");
        });

        //ComdataUtil.ajaxpostnormal('/admin/message/'+id,{},function(data){
        //
        //},"DELETE");
    }




    this.addNew = function(){
        openModel(0);
    }
    this.getItem = function(item){
        //openModel();
        ComdataUtil.loadContainer("actionmodifyform",item);
    }
    this.editTarget = function(id){
        openModel();
        ComdataUtil.ajaxpostnormal('/admin/sysparam/'+id,{},this.getItem,"GET");

    }

    this.openModel = function(type) {
        ComdataUtil.clear("actionmodifyform");
        if(type == 0){
            //新增操作
            $("#name").attr("disabled",false);

        }else{
            $("#name").attr("disabled",true);

        }
        $("#sysparam_modal").modal('show');
    }
    this.closeModel = function() {
        $("#sysparam_modal").modal('hide');
    }


    this.submit = function(){
        $('#com_message').html("");
        var data = ComdataUtil.collectData("actionmodifyform");
        ComdataUtil.ajaxpost('/admin/sysparam',data,this.finishAjaxLoadBack);
    }
    this.finishAjaxLoadBack = function(response){
        if(response.code == 500){
            $('#com_message').attr("class","text-danger text-center");
            $('#com_message').html(response.res_data);
        }else{
            ComdataUtil.clear("actionmodifyform");
            closeModel();
            this.$table.rdraw();
        }

    }
    this.resetCategory = function(){
        ComdataUtil.clear("actionmodifyform");
    }

    return this;
})(jQuery);

